﻿using System;

public class Command : System.Windows.Input.ICommand
{
    private readonly Action<object> _execute;
    private readonly Predicate<object> _canExecute;

    public Command(Action<object> execute, Predicate<object> canExecute)
    {
        _execute = execute;
        _canExecute = canExecute;
    }

    public Command(Action<object> execute) : this(execute, x => true) { }

    public void Execute(object x) { _execute(x); }

    public bool CanExecute(object x) { return _canExecute(x); }

    public event EventHandler CanExecuteChanged;

    public void RaiseCanExecuteChanged()
    {
        var handler = CanExecuteChanged;
        if (handler != null)
        {
            handler(this, EventArgs.Empty);
        }
    }
}
